<template>
  <el-form :rules="rules" :model="phone" ref="formRef">
    <el-form-item label="手机号" prop="number">
      <el-input type="text" v-model="phone.number" />
    </el-form-item>
    <el-form-item label="验证码" prop="code">
      <div class="phone-code">
        <el-input type="text" v-model.number="phone.code" />
        <el-button type="primary" class="code-btn">获取验证码</el-button>
      </div>
    </el-form-item>
  </el-form>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { ElForm } from 'element-plus'
import { rules } from '../config/phone.config'

export default defineComponent({
  setup() {
    const phone = reactive({
      number: '',
      code: ''
    })

    const formRef = ref<InstanceType<typeof ElForm>>()
    const loginAction = () => {
      formRef.value?.validate((valid) => {
        if (valid) {
          console.log('手机登录')
        }
      })
    }

    return {
      phone,
      rules,
      formRef,
      loginAction
    }
  }
})
</script>

<style lang="less" scoped>
.phone-code {
  display: flex;
  justify-content: center;
  align-items: center;
}

.code-btn {
  margin-left: 10px;
}
</style>
